<?php $products = isset($products) ? $products :array();?>
<div class='container-fluid'>
<?php echo View::make('share.backend_nav')->with('nav', Config::get('app.nav.product.sub'));?>
<div class='board'>
<div class='search' style='height:120px;min-height:120px;border:3px solid #ddd;'>
<div class='header'>
    <p>条件搜索</p>
</div>
<div class='condition'>
  <form style='margin-left:10px;margin-top:10px;' method='get' id='search_form'>
    <div class="control-group">
    <label for='cid'>淘宝商品类型&nbsp;<a class='label label-success' href='javascript:void(0)'>更新</a></label>
    <select name='cid'>
      <option value=0>请选择</option>
      <?php $cates = Tcate::all();?>
      <?php $cid = intval(Input::get('cid', 0));?>
      <?php foreach ($cates as $c):?>
      <option <?php if ($c->cid == $cid) echo 'selected="selected"'?> value='<?php echo $c->cid;?>'><?php echo $c->name;?></option>

      <?php endforeach;?>
    </select>
    </div>
    <div class="control-group">
      <label for='keyword'>关键字</label>
      <?php $keyword = strval(Input::get('keyword', ''));?>
      <input type='text' name='keyword' value='<?php echo $keyword;?>' autocomplete='off' class='input-small'/>
    </div>
    <div class="control-group">
      <div class="input-append">
      <label for='end_coupon_rate'>折扣率上限</label>
      <?php $end_coupon_rate = intval(Input::get('end_coupon_rate', 70));?>
      <input type='text' name='end_coupon_rate' class='input-mini' value='<?php echo $end_coupon_rate;?>' autocomplete='off'/>
      <span class="add-on">%</span>
      </div>
    </div>
    <div class="control-group">
      <label for='start_coupon_rate'>折扣率下限</label>
      <div class="input-append">
      <?php $start_coupon_rate = intval(Input::get('start_coupon_rate', 10));?>
      <input type='text' name='start_coupon_rate' class='input-mini' value='<?php echo $start_coupon_rate;?>' autocomplete='off'/>
      <span class="add-on">%</span>
      </div>
    </div>
    <div class="control-group">
      <label for='sort'>排序</label>
      <?php 
        $sort = Input::get('sort', 'default');
        $sort_array = array(
          'default' => '默认排序',
          'price_desc' => '折扣价格从高到低',
          'price_asc'  => '折扣价格从低到高',
          'credit_desc'=> '信用等级从高到低',
          'credit_asc' => '信用等级从低到高',
          'commissionRate_desc' => '佣金比率从高到低',
          'commissionRate_asc'  => '佣金比率从低到高',
          'volume_desc' => '成交量从高到低',
          'volume_asc' => '成交量从低到高'
        );
      ?>
      <select name='sort' class='span2'>
      <?php foreach ($sort_array as $k => $v):?>
        <option <?php if($sort == $k) echo 'selected="selected"'?>value='<?php echo $k;?>'><?php echo $v;?></option>
      <?php endforeach;?>
      </select>
    </div>
    <div class="control-group">
      <button type='submit' class='btn btn-success' style='margin-top:25px;'>搜索</button>
    </div>
    <div style='clear:both;'></div>
  </form>
</div>
</div>
<div style='height:10px;'></div>
<div class='auto' style='height:120px;min-height:120px;border:3px solid #ddd;'>
<div class='header'>
    <p>添加设置</p>
</div>
  <form style='margin-left:10px;margin-top:10px;' method='post' id='add_form'>
    <div class="control-group">
    <label for='category_id'>商品类型</label>
    <select name='category_id'>
      <option value=0>请选择</option>
      <?php $cates = Category::all();?>
      <?php foreach ($cates as $c):?>
      <option value='<?php echo $c->id;?>'><?php echo $c->cname;?></option>
      <?php endforeach;?>
    </select>
    </div>

    <div class="control-group">
      <label for='tag'>Tag</label>
      <?php $tag = strval(Input::get('tag', ''));?>
      <input type='text' name='tag' class='input' value='<?php echo $tag?>' autocomplete='off'/>
    </div>

    <div class="control-group">
<?php 
$detail = array();
$detail['cid'] = $cid;
$detail['keyword'] = $keyword;
$detail['start_coupon_rate'] = $start_coupon_rate;
$detail['end_coupon_rate'] = $end_coupon_rate;
?>
      <a class='btn btn-success' style='margin-top:25px;' id='set_auto' data-detail='<?php echo json_encode($detail)?>'>设为自动</a>
    </div>
    <div style='clear:both;'></div>
  </form>
</div>
<div style='height:10px;'></div>
<?php if ($products):?>
<span class='label label-info'>商品列表</span>
<a href='javascript:void(0)' class='label label-success pull-right batch_add'>批量推广</a>
<table class='table table-bordered table-striped'>
  <thead>
    <tr>
      <th><input type='checkbox' class='product'/></th>
      <th class='img'>#Img</th>
      <th class='title'>#标题</th>
      <th class='price'>#价格</th>
      <th class='coupon_price'>#折扣价</th>
      <th class='coupon_rate'>#折扣率</th>
      <th class='start_time'>#开始时间</th>
      <th class='end_time'>#结束时间</th>
      <th class='op'>#OP</th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($products->taobaoke_item as $i):?>
    <?php $exist = false; if (Product::where('title', '=', $i->title)->first()) $exist = true;?>
    <tr <?php if ($exist) echo 'class="success"';?> data-num-iid='<?php echo $i->num_iid;?>' data-pic-url='<?php echo $i->pic_url;?>' data-coupon-rate='<?php echo $i->coupon_rate;?>' data-title='<?php echo $i->title;?>' data-url='<?php echo trim($i->click_url);?>' data-price='<?php echo $i->price;?>' data-coupon-price='<?php echo $i->coupon_price;?>' data-coupon-start-time='<?php echo $i->coupon_start_time;?>' data-coupon-end-time='<?php echo $i->coupon_end_time;?>' data-mall='taobao'> 
      <td><input type='checkbox' class='product' /></td>
      <td><?php echo "<a href='{$i->click_url}' target='_blank'><img src='{$i->pic_url}_120x120.jpg' style='height:76px;' /></a>"?></td>
      <td><p style='font-size:12px;'><?php echo "<a href='{$i->click_url}' target='_blank'>{$i->title}</a>";?></p></td>
      <td><?php echo $i->price;?></td>
      <td><?php echo $i->coupon_price;?></td>
      <td><?php echo floatval($i->coupon_rate)/100 . '%';?></td>
      <td><?php echo $i->coupon_start_time;?></td>
      <td><?php echo $i->coupon_end_time;?></td>
      <td>
        <?php if (!$exist):?>
        <a class='btn btn-mini btn-success pick' href='javascript:void(0)'>推广</a>
        <a class='btn btn-mini btn-danger unpick hide' href='javascript:void(0)'>取消</a>
        <?php else:?>
        <a class='btn btn-mini btn-success pick hide' href='javascript:void(0)'>推广</a>
        <a class='btn btn-mini btn-danger unpick' href='javascript:void(0)'>取消</a>
        <?php endif;?>
      </td>
    </tr>
    <?php endforeach;?>
  </tbody>
</table>
    <div class="pagination pull-right">
      <ul><?php echo $page;?></ul>
    </div>
<?php endif;?>
</div>
</div>
<style>
</style>
